﻿layui.use(["layer", "element", "laytpl", "form"], function() {
    var layer = layui.layer;
    var layelement = layui.element;
    var laytpl = layui.laytpl;
    var layform = layui.form;
    layer.msg("hi!");

    // 加载links
    // loadLinks();
    var data = {
        links: [{
                title: "old blog",
                url: "https://my.oschina.net/jannn/blog/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "new blog",
                url: "https://my.oschina.net/taadis/blog/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "gitee",
                url: "https://gitee.com/taadis/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "github",
                url: "https://github.com/taadis/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "cnblogs",
                url: "https://www.cnblogs.com/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "aliyun",
                url: "https://www.aliyun.com/",
                description: "",
                backgroundColor: ""
            },
            {
                title: "JSFiddle",
                url: 'https://jsfiddle.net/user/dashboard/fiddles/',
                description: "",
                backgroundColor: ""
            },
            {
                title: "Vue.js",
                url: "https://cn.vuejs.org/index.html",
                description: "",
                backgroundColor: ""
            },
            {
                title: "ElementUI",
                url: "http://element-cn.eleme.io/#/zh-CN",
                description: "",
                backgroundColor: ""
            }
        ]
    };

    for (var i = 0, n = data.links.length; i < n; i++) {
        var link = data.links[i];
        link.backgroundColor = getRandomLayuiBgColor();
    }
    console.log(data);

    var tpl = document.getElementById("laytplLinks").innerHTML;
    laytpl(tpl).render(data, function(html) {
        document.getElementById("links").innerHTML = html;
    });

    //
    //getRandomLayuiBgColor(); //ok


    // 我的博客RSS
    $('#old-blog').FeedEk({
        FeedUrl: 'https://my.oschina.net/jannn/rss',
        MaxCount: 5,
        ShowDesc: true,
        ShowPubDate: true,
        DescCharacterLimit: 100,
        TitleLinkTarget: '_blank',
    });

    // 我的博客RSS
    $('#new-blog').FeedEk({
        FeedUrl: 'https://my.oschina.net/taadis/rss',
        MaxCount: 5,
        ShowDesc: true,
        ShowPubDate: true,
        DescCharacterLimit: 100,
        TitleLinkTarget: '_blank',
    });

    //...

    // layui 的所有背景色
    function getLayuiBgColor() {
        var data = [
            "", //默认,一般为透明,在徽章layui-badge中表现为赤色
            "layui-bg-orange", //橙
            "layui-bg-green", //绿
            //"layui-bg-cyan", //青,暂时不要,颜色太深,字体看不见
            "layui-bg-blue", //蓝
            //"layui-bg-black", //黑,暂时不要,字体会看不见
            "layui-bg-gray" //灰
        ];
        return data;
    }

    // 获取 layui 背景色中的随机一个
    function getRandomLayuiBgColor() {
        var colors = getLayuiBgColor();
        var index = Math.floor(Math.random() * colors.length);
        var color = colors[index];
        return color;
    }

    //...
});